package com.apabi.publisher;

import java.io.*;
import java.util.jar.*;

public class TestGenerateJar {

	public static void main(String[] args)throws Exception
	{
		int total = 4;
		File[] files = new File[4];
		for(int i=0;i<total;i++)
		{
			files[i]= new File("javabook/"+Integer.toString(i+1));
		}
		
		File file  = new File("testJar.jar");
		if(file.exists()){
			file.delete();
		}
		file.createNewFile();
		FileOutputStream fos = new FileOutputStream(file);
		
		Manifest mani = new Manifest();
		Attributes a = mani.getMainAttributes();
		a.putValue("Manifest-Version", "1.0");
		a.putValue("MicroEdition-Configuration", "CLDC-1.0");
		a.putValue("MIDlet-Version", "1.0");
		a.putValue("MIDlet-Vendor", "APABI.COM");
		a.putValue("MicroEdition-Profile", "MIDP-1.0");
		
		
		JarOutputStream jarout = new JarOutputStream(fos,mani);
		
		byte[] buffer =new byte[1024];
		//int bytesread;
		
		for(int i=0;i<total;i++)
		{
			JarEntry jar = new JarEntry(Integer.toString(i+1));
			File ff = files[i];
			FileInputStream fis = new FileInputStream(ff);
			
			jarout.putNextEntry(jar);
			int n=0;
			while( (n=fis.read(buffer)) != -1)
			{
				jarout.write(buffer,0,n);
			}
			fis.close();
			jarout.flush();
		}
		jarout.flush();
		jarout.closeEntry();
	}
}
